import requests
import app


class ComApi:
    def __init__(self):
        # 商品分类
        self.category_url = app.host_url + "category/all"
        # 商品分类下的商品
        self.by_category_url = app.host_url + "product/by_category"
        # 获取商品信息
        self.product_url = app.host_url + "product/{}"

    def CatApi(self):
        return requests.get(self.category_url)

    def ByApi(self, id=2):
        data = {"id": id}
        return requests.get(self.by_category_url, params=data)

    def ProductApi(self, id=2):
        return requests.get(self.product_url.format(id))
